class ReqDocsController < ApplicationController

  before_filter 'verify_session'

  def index
    @docs = ReqDoc.find(:all, :conditions=>["project_id=?",@p_id])
  end
  
  def add_form
    @doc = ReqDoc.new
    render(:partial=>'add_form')
  end 
  
  def create
    doc = ReqDoc.new(params[:doc])
    doc.project_id = @p_id
    doc.save
    redirect_to :action=>:index
  end

  def edit_form
    @doc = ReqDoc.find(params[:id])
    render(:partial=>'edit_form')
  end 
  
  def edit
    if !params[:doc].include?( 'Cancel' )
      doc = ReqDoc.find(params[:id])
      doc.update_attributes(params[:doc]) # do a save
    end
    redirect_to :action=>:index
  end


private

  def verify_session
    raise 'not logged' if session['user'] == nil 
    @p_id = session[:selected_project]
  end

end
